import request from '@/utils/request'

// ====================菜单====================
// 获取当前保存的公众号菜单
export function getPublicMenuByData() {
  const appId = 'wxa960e74c40381596'
  return request({
    url: '/mp/menu/' + appId,
    method: 'get'
  })
}

// 保存发布菜单
export function savePublicMenu(buttons) {
  const appId = 'wxa960e74c40381596'
  return request({
    url: '/mp/menu/' + appId,
    method: 'post',
    data: buttons
  })
}

// 同步当前实时的公众号菜单
export function getPublicMenuByWechat() {
  const appId = 'wxa960e74c40381596'
  return request({
    url: '/mp/menu/current',
    method: 'get',
    params: { appId }
  })
}

// 根据key获取对应素材信息
export function getMaterialByKey(key) {
  return request({
    url: '/mp/message/clickContent',
    method: 'get',
    params: { key }
  })
}

// 保存菜单与对应的回复内容的映射
export function setKeyByMaterial(params) {
  params.appId = 'wxa960e74c40381596'
  return request({
    url: '/mp/message/clickContent',
    method: 'post',
    data: params
  })
}

// ====================素材====================
// 获取图文素材列表
export function getMaterialList(params) {
  params.shopId = '123'
  return request({
    url: '/mp/message/articles',
    method: 'get',
    params: params
  })
}

// 根据ID删除图文素材
export function delMaterialById(id) {
  return request({
    url: '/mp/message/article/' + id,
    method: 'delete',
    params: { shopId: 123 }
  })
}

// 新增图文素材素材(有ID则是编辑)
export function addMaterial(form) {
  // title, picUrl, description, url
  form.shopId = 123
  return request({
    url: '/mp/message/article',
    method: 'post',
    data: form
  })
}

// ====================文本消息====================
// 获取公众号下配置的回复内容
export function getReplylList(page = 1, pageSize = 10) {
  const params = {}
  params.appId = 'wxa960e74c40381596'
  params.page = page
  params.pageSize = pageSize
  return request({
    url: '/mp/message/replyInfoList',
    method: 'get',
    params: params
  })
}

// 增加或者修改公众号下配置的回复内容
export function addReply(form) {
  // appId, content, id, keyword,type
  form.appId = 'wxa960e74c40381596'
  return request({
    url: '/mp/message/replyInfo',
    method: 'post',
    data: form
  })
}

// 根据ID删除公众号设置的文本回复
export function delReply(id) {
  const params = {}
  params.appId = 'wxa960e74c40381596'
  params.id = id
  return request({
    url: '/mp/message/replyInfo',
    method: 'delete',
    params: params
  })
}

// 根据关键字查询对应的回复内容
export function searchReply(keyword) {
  const params = {}
  params.appId = 'wxa960e74c40381596'
  params.keyword = keyword
  return request({
    url: '/mp/message/keyReply',
    method: 'get',
    params: params
  })
}

// ====================授权====================
export function getWechaAuthUrl(params) {
  return request({
    url: '/open/auth/preAuthUrl',
    method: 'get',
    params: params
  })
}

